package redis

import (
	"fmt"
	"gitee.com/captials-team/ubdframe/src/domain/configstc"
	"github.com/go-redis/redis/v8"
	"time"
)

func NewRedisClient(c configstc.DBConfig) *redis.Client {
	rd := redis.NewClient(&redis.Options{
		Network:         "",
		Addr:            fmt.Sprintf("%s:%s", c.DbHost, c.DbPort),
		Username:        c.DbUser,
		Password:        c.DbPassword,
		DB:              0,
		MaxRetries:      0,
		MinRetryBackoff: 0,
		MaxRetryBackoff: 0,
		DialTimeout:     0,
		ReadTimeout:     time.Second * 10,
		WriteTimeout:    time.Second * 10,
		IdleTimeout:     time.Second * time.Duration(c.MaxIdleTime),
	})

	return rd
}
